//
//  JobDetailViewController.m
//  MagictoHire
//
//  Created by 锋 on 2017/12/19.
//  Copyright © 2017年 HUAYU. All rights reserved.
//

#import "JobDetailViewController.h"
#import "JobDetailMessageTableViewCell.h"
#import "JobProducePointTableViewCell.h"
#import "EvaluateProducePointTableViewCell.h"
#import "RecommendJobDetailTableViewCell.h"
#import "RecommendPointTableViewCell.h"
#import "JobDetailModel.h"
#import "SpotsModel.h"
#import "WorkModel.h"
#import "EvaluateModel.h"
#import "EvaluateSpotsModel.h"
#import "SelectWorkerViewController.h"
#import "DataPicturesViewController.h"
#import "AppraiseViewController.h"
#import "WorkerMessagesViewController.h"

@interface JobDetailViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *jobDetailTableView;
@property (nonatomic, strong) UILabel *jobKindLabel;
@property (nonatomic, strong) NSArray *nameArr;
@property (nonatomic, strong) NSArray *jobDetailArr;
@property (nonatomic, assign) BOOL isSetUp;
@property (nonatomic, assign) BOOL isSetUpWorker;
@property (nonatomic, strong) UIButton *recommendRightBtn;
@end

@implementation JobDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _isSetUp = NO;
    _isSetUpWorker = NO;
    self.nameArr = @[@"Bom资料", @"收货地址", @"物流费用", @"包装费用", @"包装详细", @"包装说明"];
    [self setupUI];
    [self setupFillDataTableView];
    [self requestJobDetailData];
    // Do any additional setup after loading the view.
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self requestJobDetailData];
    [self.jobDetailTableView reloadData];
}

- (void)setupUI {
    if (_detailType == CHECKTYPE) {
        UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc] initWithTitle:@"验收" style:UIBarButtonItemStylePlain target:self action:@selector(onClickCheckJob)];
        [rightBtn setTintColor:[UIColor whiteColor]];
        [rightBtn setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:15], UITextAttributeFont,nil] forState:UIControlStateNormal];
        self.navigationItem.rightBarButtonItem = rightBtn;
    } else if (_detailType == RECOMMENDTYPE) {
        if (_statusNum == 4) {
            UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc] initWithTitle:@"确定" style:UIBarButtonItemStylePlain target:self action:@selector(onClickEnsureProject)];
            [rightBtn setTintColor:[UIColor whiteColor]];
            [rightBtn setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:15], UITextAttributeFont,nil] forState:UIControlStateNormal];
            self.navigationItem.rightBarButtonItem = rightBtn;
        }
    }
    self.navigationController.navigationBar.translucent = NO;
    self.navigationItem.title = @"项目详情";
    self.view.backgroundColor = BacksColor;
}
- (void)setupFillDataTableView {
    _jobDetailTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - STA_NAV_HEIGHT - SCREER_HeiX) style:UITableViewStyleGrouped];
    _jobDetailTableView.delegate = self;
    _jobDetailTableView.dataSource = self;
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 0.000001)];
    view.backgroundColor = [UIColor whiteColor];
    _jobDetailTableView.tableHeaderView = view;
    _jobDetailTableView.tableFooterView = view;
    _jobDetailTableView.backgroundColor = BacksColor;
    if (@available(iOS 11.0, *)) {
        _jobDetailTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    _jobDetailTableView.estimatedRowHeight = 0;
    _jobDetailTableView.estimatedSectionHeaderHeight = 0;
    _jobDetailTableView.estimatedSectionFooterHeight = 0;
    [self.view addSubview:_jobDetailTableView];
}

- (void)requestJobDetailData {
    WEAKSELF;
    NSDictionary *dic;
    if (_detailType == EVALUATETYPE) {
        dic = @{@"id" : _ID, @"queryEvaluate" : @"1"};
    } else {
        dic = @{@"id" : _ID};
    }
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [HYBaseHandler requestProjectDetailParmers:dic Success:^(id obj)
     {
         [MBProgressHUD hideAllHUDsForView:weakSelf.view animated:YES];
         if ([obj server_Getcodecheck])
         {
             NSLog(@"%@", obj);
             if (_detailType == EVALUATETYPE) {
                 _jobDetailArr = [EvaluateModel mj_objectArrayWithKeyValuesArray:@[obj[@"data"]]];
             } else {
                 _jobDetailArr = [JobDetailModel mj_objectArrayWithKeyValuesArray:@[obj[@"data"]]];
             }
             JobDetailModel *detailModel = _jobDetailArr[0];
             BOOL isEnsure = NO;
             if (detailModel.spots.count > 0) {
                 for (int i = 0; i<detailModel.spots.count; i++) {
                     SpotsModel *model = detailModel.spots[i];
                     if (model.workerName && ![model.workerName isKindOfClass:[NSNull class]]) {
                         isEnsure = YES;
                     } else {
                         isEnsure = NO;
                     }
                 }
             }
             if (isEnsure) {
                 if (_statusNum == 4) {
                     UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc] initWithTitle:@"确定" style:UIBarButtonItemStylePlain target:self action:@selector(onClickEnsureProject)];
                     [rightBtn setTintColor:[UIColor whiteColor]];
                     [rightBtn setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:15], UITextAttributeFont,nil] forState:UIControlStateNormal];
                     self.navigationItem.rightBarButtonItem = rightBtn;
                 }
             }
             
             WEAKSELF;
             dispatch_async(dispatch_get_main_queue(), ^{
                 [weakSelf.jobDetailTableView reloadData];
             });
         }
         else
         {
             [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
         }
     } failed:^(NSError *error) {
         [MBProgressHUD hideAllHUDsForView:weakSelf.view animated:YES];
         
     }];
}

// MARK:tableview的方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 4;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (_detailType == CHECKTYPE) {
        if (section == 0 || section == 1) {
            return 2;
        } else if (section == 2) {
            JobDetailModel *detailModel = _jobDetailArr[0];
            return detailModel.spots.count + 1;
        } else if (section == 3) {
            return _nameArr.count;
        }
    } else if (_detailType == EVALUATETYPE) {
        if (section == 0 || section == 1) {
            return 2;
        } else if (section == 2) {
            JobDetailModel *detailModel = _jobDetailArr[0];
            return detailModel.spots.count + 1;
        } else if (section == 3) {
            return _nameArr.count;
        }
    } else if (_detailType == RECOMMENDTYPE) {
        if (section == 0 || section == 1) {
            return 2;
        } else if (section == 2) {
            JobDetailModel *detailModel = _jobDetailArr[0];
            return detailModel.spots.count + 1;
        } else if (section == 3) {
            return _nameArr.count;
        }
    }
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (_detailType == CHECKTYPE) {
        if (indexPath.section == 0 || indexPath.section == 1) {
            if (indexPath.row == 0) {
                return 50;
            } else {
                return 78;
            }
        } else {
            return 44;
        }
    } else if (_detailType == EVALUATETYPE) {
        EvaluateModel *evaluateModel = _jobDetailArr[0];
        if (indexPath.section == 0) {
            if (indexPath.row == 0) {
                return 50;
            } else {
                return 78;
            }
        } else if (indexPath.section == 1) {
            if (indexPath.row == 0) {
                return 50;
            } else {
                return 110 + evaluateModel.machines.count * 20 + 30 + 20 + evaluateModel.workGroups.count * 20 + 30;
            }
        } else {
            return 44;
        }
    } else if (_detailType == RECOMMENDTYPE) {
        if (indexPath.section == 0 || indexPath.section == 1) {
            if (indexPath.row == 0) {
                return 50;
            } else {
                return 78;
            }
        } else {
            return 44;
        }
    }
    return 0;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section != 0) {
        return 5;
    } else {
        return 0.000001;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.000001;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (_detailType == CHECKTYPE) {
        JobDetailModel *detailModel = _jobDetailArr[0];
        if (indexPath.section == 0) {
            if (indexPath.row == 0) {
                NSString *ID = @"cellID";
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
                if (!cell) {
                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:ID];
                }
                if (!_jobKindLabel) {
                    _jobKindLabel = [[UILabel alloc] initWithFrame:CGRectMake(13, 0, 130, 50)];
                    _jobKindLabel.textColor = UIColorHexValue(0x8194C4);
                    _jobKindLabel.font = [UIFont systemFontOfSize:16];
                    [cell.contentView addSubview:_jobKindLabel];
                    UILabel *datelabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 150 - 12, 0, 150, 50)];
                    datelabel.tag = 600 + indexPath.row;
                    datelabel.textAlignment = NSTextAlignmentRight;
                    datelabel.textColor = UIColorHexValue(0x999999);
                    datelabel.font = [UIFont systemFontOfSize:12];
                    [cell.contentView addSubview:datelabel];
                }
                _jobKindLabel.text = detailModel.name;
                UILabel *datelabel = [cell.contentView viewWithTag:600 + indexPath.row];
                datelabel.text = [NSString stringWithFormat:@"%@-%@", detailModel.startDate, detailModel.endDate];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                
                return cell;
            } else {
                JobDetailMessageTableViewCell *cell = [[NSBundle mainBundle] loadNibNamed:@"JobDetailMessageTableViewCell" owner:self options:nil].lastObject;
                cell.nameLabel.text = detailModel.employerName;
                cell.kindLabel.text = detailModel.productCategoryName;
                cell.moneyLabel.text = detailModel.budget;
                cell.evaluateBtn.hidden = YES;
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                
                return cell;
            }
        } else if (indexPath.section == 1) {
            if (indexPath.row == 0) {
                NSString *ID = @"cellID1";
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
                if (!cell) {
                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:ID];
                }
                if (![cell.contentView viewWithTag:100 + indexPath.row]) {
                    UILabel *positionlabel = [[UILabel alloc] initWithFrame:CGRectMake(14, 0, 120, 50)];
                    positionlabel.textColor = UIColorHexValue(0x4D4D4D);
                    positionlabel.tag = 100 + indexPath.row;
                    positionlabel.font = [UIFont systemFontOfSize:15];
                    positionlabel.text = @"岗位描述";
                    [cell.contentView addSubview:positionlabel];
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                
                return cell;
            } else {
                NSString *ID = @"cellID2";
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
                if (!cell) {
                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:ID];
                }
                if (![cell.contentView viewWithTag:200 + indexPath.row]) {
                    UILabel *produceDetailLabel = [[UILabel alloc] initWithFrame:CGRectMake(14, 20, 120, 20)];
                    produceDetailLabel.textColor = UIColorHexValue(0x4D4D4D);
                    produceDetailLabel.tag = 200 + indexPath.row;
                    produceDetailLabel.text = @"生产说明:";
                    produceDetailLabel.font = [UIFont systemFontOfSize:13];
                    [cell.contentView addSubview:produceDetailLabel];
                }
                if (![cell.contentView viewWithTag:300 + indexPath.row]) {
                    UILabel *produceLabel = [[UILabel alloc] init];
                    produceLabel.textColor = UIColorHexValue(0x999999);
                    produceLabel.tag = 300 + indexPath.row;
                    produceLabel.font = [UIFont systemFontOfSize:13];
                    produceLabel.numberOfLines = 0;
                    produceLabel.frame = CGRectMake(14, 40, SCREEN_WIDTH - 28, 20);
                    [cell.contentView addSubview:produceLabel];
                }
                UILabel *produceLabel = [cell.contentView viewWithTag:300 + indexPath.row];
                produceLabel.text = detailModel.remark;
                CGRect textViewHeight = [Utilities calculateWidthAndHeightWithWidth:SCREEN_WIDTH - 28 height:1000 text:detailModel.remark font:[UIFont systemFontOfSize:13]];
                CGFloat aHeight = textViewHeight.size.height - 20 > 0 ? textViewHeight.size.height - 20 : 0;
                CGFloat height = 20 + aHeight;
                if (height > 40) {
                    height = 40;
                }
                produceLabel.frame = CGRectMake(14, 40, SCREEN_WIDTH - 28, height);
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                
                return cell;
            }
        } else if (indexPath.section == 2) {
            if (indexPath.row == 0) {
                NSString *ID = @"cellID3";
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
                if (!cell) {
                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:ID];
                }
                if (![cell.contentView viewWithTag:400 + indexPath.row]) {
                    UILabel *producePointLabel = [[UILabel alloc] initWithFrame:CGRectMake(14, 0, 120, 44)];
                    producePointLabel.textColor = UIColorHexValue(0x4D4D4D);
                    producePointLabel.text = @"生产节点";
                    producePointLabel.tag = 400 + indexPath.row;
                    producePointLabel.font = [UIFont systemFontOfSize:15];
                    [cell.contentView addSubview:producePointLabel];
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                
                return cell;
            } else {
                JobProducePointTableViewCell *cell = [[NSBundle mainBundle] loadNibNamed:@"JobProducePointTableViewCell" owner:self options:nil].lastObject;
                cell.signBtn.imageView.layer.cornerRadius = 15;
                cell.signBtn.imageView.layer.masksToBounds = YES;
                cell.signBtn.tag = indexPath.row;
                if (indexPath.row == 1) {
                    [cell.signBtn setImage:[UIImage imageNamed:@"guanlizhe"] forState:UIControlStateNormal];
                } else {
                    [cell.signBtn setTitle:[NSString stringWithFormat:@"%ld", indexPath.row - 1] forState:UIControlStateNormal];
                }
                if (detailModel.spots.count > 0) {
                    SpotsModel *model = detailModel.spots[indexPath.row - 1];
                    cell.nameLabel.text = model.workerName;
                    cell.produceNameLabel.text = model.workName;
                    [cell.signBtn sd_setImageWithURL:[NSURL URLWithString:model.workerIcon] forState:UIControlStateNormal];
                    [cell.signBtn addTarget:self action:@selector(onClickSignBtn:) forControlEvents:UIControlEventTouchUpInside];
                    if (model.wage && ![model.wage isKindOfClass:[NSNull class]] && model.wage.length>0) {
                        cell.priceLabel.text = [NSString stringWithFormat:@"%@元/小时", model.wage];
                    } else {
                        cell.priceLabel.text = [NSString stringWithFormat:@"%@元/小时", model.forecastWage];
                    }
                    [cell.timeBtn setTitle:[NSString stringWithFormat:@"%@小时", model.hours] forState:UIControlStateNormal];
                }
                if (indexPath.row == detailModel.spots.count) {
                    cell.lineLabel.hidden = YES;
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                
                return cell;
            }
        } else if (indexPath.section == 3) {
            UITableViewCell *cell = [[UITableViewCell alloc] init];
            if (![cell.contentView viewWithTag:500 + indexPath.row]) {
                UILabel *detailNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(110, 0, SCREEN_WIDTH - 110 - 33, 44)];
                detailNameLabel.numberOfLines = 0;
                detailNameLabel.textColor = UIColorHexValue(0x4D4D4D);
                detailNameLabel.tag = 500 + indexPath.row;
                detailNameLabel.font = [UIFont systemFontOfSize:14];
                [cell.contentView addSubview:detailNameLabel];
            }
            UILabel *detailNameLabel = [cell.contentView viewWithTag:500 + indexPath.row];
            if (indexPath.row == 1) {
                detailNameLabel.text = detailModel.deliveryAddress;
            } else if (indexPath.row == 2) {
                detailNameLabel.text = [NSString stringWithFormat:@"￥%@", detailModel.expressFee];
            } else if (indexPath.row == 3) {
                detailNameLabel.text = [NSString stringWithFormat:@"￥%@", detailModel.packingFee];
            } else if (indexPath.row == 4) {
                detailNameLabel.text = detailModel.packRemark;
            } else if (indexPath.row == 5) {
                if ([detailModel.packType isEqualToString:@"1"]) {
                    detailNameLabel.text = @"简易包装";
                } else if ([detailModel.packType isEqualToString:@"2"]) {
                    detailNameLabel.text = @"专业包装";
                }
            }
            
            if (indexPath.row == 0) {
                detailNameLabel.text = [NSString stringWithFormat:@"%ld张", detailModel.bomImgs.count];
                detailNameLabel.textAlignment = NSTextAlignmentRight;
                cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            } else {
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
            }
            cell.textLabel.textColor = UIColorHexValue(0x4D4D4D);
            cell.textLabel.font = [UIFont systemFontOfSize:15];
            cell.textLabel.text = _nameArr[indexPath.row];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            return cell;
        }
    } else if (_detailType == EVALUATETYPE) {
        EvaluateModel *evaluateModel = _jobDetailArr[0];
        if (indexPath.section == 0) {
            if (indexPath.row == 0) {
                NSString *ID = @"cellID";
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
                if (!cell) {
                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:ID];
                }
                if (!_jobKindLabel) {
                    _jobKindLabel = [[UILabel alloc] initWithFrame:CGRectMake(13, 0, 130, 50)];
                    _jobKindLabel.textColor = UIColorHexValue(0x8194C4);
                    _jobKindLabel.font = [UIFont systemFontOfSize:16];
                    [cell.contentView addSubview:_jobKindLabel];
                    UILabel *datelabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 150 - 12, 0, 150, 50)];
                    datelabel.tag = 600 + indexPath.row;
                    datelabel.textAlignment = NSTextAlignmentRight;
                    datelabel.textColor = UIColorHexValue(0x999999);
                    datelabel.font = [UIFont systemFontOfSize:12];
                    [cell.contentView addSubview:datelabel];
                }
                _jobKindLabel.text = evaluateModel.name;
                UILabel *datelabel = [cell.contentView viewWithTag:600 + indexPath.row];
                datelabel.text = [NSString stringWithFormat:@"%@-%@", evaluateModel.startDate, evaluateModel.endDate];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                
                return cell;
            } else {
                JobDetailMessageTableViewCell *cell = [[NSBundle mainBundle] loadNibNamed:@"JobDetailMessageTableViewCell" owner:self options:nil].lastObject;
                cell.nameLabel.text = evaluateModel.employerName;
                cell.kindLabel.text = evaluateModel.productCategoryName;
                cell.moneyLabel.text = evaluateModel.budget;
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                [cell.evaluateBtn addTarget:self action:@selector(onClickEvaluateEmployerBtn) forControlEvents:UIControlEventTouchUpInside];
                if ([evaluateModel.employerEvaluated isEqual:@"1"]) {
                    [cell.evaluateBtn setTitle:@"已评价" forState:UIControlStateNormal];
                    [cell.evaluateBtn setBackgroundColor:RGB(179, 179, 179)];
                }
                
                return cell;
            }
        } else if (indexPath.section == 1) {
            if (indexPath.row == 0) {
                NSString *ID = @"cellID1";
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
                if (!cell) {
                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:ID];
                }
                if (![cell.contentView viewWithTag:100 + indexPath.row]) {
                    UILabel *positionlabel = [[UILabel alloc] initWithFrame:CGRectMake(14, 0, 120, 50)];
                    positionlabel.textColor = UIColorHexValue(0x4D4D4D);
                    positionlabel.tag = 100 + indexPath.row;
                    positionlabel.font = [UIFont systemFontOfSize:15];
                    positionlabel.text = @"岗位描述";
                    [cell.contentView addSubview:positionlabel];
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                
                return cell;
            } else {
                NSString *ID = @"cellID2";
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
                if (!cell) {
                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:ID];
                }
                if (![cell.contentView viewWithTag:200 + indexPath.row]) {
                    UILabel *produceDetailLabel = [[UILabel alloc] initWithFrame:CGRectMake(14, 20, 120, 20)];
                    produceDetailLabel.textColor = UIColorHexValue(0x4D4D4D);
                    produceDetailLabel.tag = 200 + indexPath.row;
                    produceDetailLabel.text = @"生产说明:";
                    produceDetailLabel.font = [UIFont systemFontOfSize:13];
                    [cell.contentView addSubview:produceDetailLabel];
                }
                if (![cell.contentView viewWithTag:300 + indexPath.row]) {
                    UILabel *produceLabel = [[UILabel alloc] init];
                    produceLabel.textColor = UIColorHexValue(0x999999);
                    produceLabel.tag = 300 + indexPath.row;
                    produceLabel.font = [UIFont systemFontOfSize:13];
                    produceLabel.numberOfLines = 0;
                    produceLabel.frame = CGRectMake(14, 40, SCREEN_WIDTH - 28, 20);
                    [cell.contentView addSubview:produceLabel];
                }
                
                if (![cell.contentView viewWithTag:700 + indexPath.row]) {
                    UILabel *produceMachineLabel = [[UILabel alloc] initWithFrame:CGRectMake(14, 90, 120, 20)];
                    produceMachineLabel.textColor = UIColorHexValue(0x4D4D4D);
                    produceMachineLabel.tag = 700 + indexPath.row;
                    produceMachineLabel.text = @"生产设备:";
                    produceMachineLabel.font = [UIFont systemFontOfSize:13];
                    [cell.contentView addSubview:produceMachineLabel];
                }
                if (!_isSetUp) {
                    for (int i = 0; i < evaluateModel.machines.count; i++) {
                        _isSetUp = YES;
                        UILabel *leftLabel = [[UILabel alloc] initWithFrame:CGRectMake(14, 110 + i * 20, (SCREEN_WIDTH - 28) / 2, 20)];
                        leftLabel.tag = 1000 + i;
                        leftLabel.textAlignment = NSTextAlignmentLeft;
                        leftLabel.textColor = UIColorHexValue(0x999999);
                        leftLabel.font = [UIFont systemFontOfSize:13];
                        [cell.contentView addSubview:leftLabel];
                        UILabel *rightLabel = [[UILabel alloc] initWithFrame:CGRectMake(14 + (SCREEN_WIDTH - 28) / 2, 110 + i * 20, (SCREEN_WIDTH - 28) / 2, 20)];
                        rightLabel.tag = 2000 + i;
                        rightLabel.textAlignment = NSTextAlignmentRight;
                        rightLabel.textColor = UIColorHexValue(0x999999);
                        rightLabel.font = [UIFont systemFontOfSize:13];
                        [cell.contentView addSubview:rightLabel];
                    }
                }
                for (int i = 0; i < evaluateModel.machines.count; i++) {
                    ProduceMachinesModel *machines = evaluateModel.machines[i];
                    UILabel *leftLabel = [cell.contentView viewWithTag:1000 + i];
                    UILabel *rightLabel = [cell.contentView viewWithTag:2000 + i];
                    leftLabel.text = machines.machine.name;
                    rightLabel.text = [NSString stringWithFormat:@"%@台", machines.count];
                }
                
                if (![cell.contentView viewWithTag:800 + indexPath.row]) {
                    UILabel *workerLabel = [[UILabel alloc] initWithFrame:CGRectMake(14, 110 + evaluateModel.machines.count * 20 + 30, 120, 20)];
                    workerLabel.textColor = UIColorHexValue(0x4D4D4D);
                    workerLabel.tag = 800 + indexPath.row;
                    workerLabel.text = @"所需工人:";
                    workerLabel.font = [UIFont systemFontOfSize:13];
                    [cell.contentView addSubview:workerLabel];
                }
                UILabel *workerLabel = [cell.contentView viewWithTag:800 + indexPath.row];
                workerLabel.frame = CGRectMake(14, 110 + evaluateModel.machines.count * 20 + 30, 120, 20);
                if (!_isSetUpWorker) {
                    for (int i = 0; i < evaluateModel.workGroups.count; i++) {
                        _isSetUpWorker = YES;
                        UILabel *leftLabel = [[UILabel alloc] initWithFrame:CGRectMake(14, 110 + i * 20 + evaluateModel.machines.count * 20 + 30 + 20, (SCREEN_WIDTH - 28) / 2, 20)];
                        leftLabel.tag = 3000 + i;
                        leftLabel.textAlignment = NSTextAlignmentLeft;
                        leftLabel.textColor = UIColorHexValue(0x999999);
                        leftLabel.font = [UIFont systemFontOfSize:13];
                        [cell.contentView addSubview:leftLabel];
                        UILabel *rightLabel = [[UILabel alloc] initWithFrame:CGRectMake(14 + (SCREEN_WIDTH - 28) / 2, 110 + i * 20 + evaluateModel.machines.count * 20 + 30 + 20, (SCREEN_WIDTH - 28) / 2, 20)];
                        rightLabel.tag = 4000 + i;
                        rightLabel.textAlignment = NSTextAlignmentRight;
                        rightLabel.textColor = UIColorHexValue(0x999999);
                        rightLabel.font = [UIFont systemFontOfSize:13];
                        [cell.contentView addSubview:rightLabel];
                    }
                }
                for (int i = 0; i < evaluateModel.workGroups.count; i++) {
                    WorkModel *model = evaluateModel.workGroups[i];
                    UILabel *leftLabel = [cell.contentView viewWithTag:3000 + i];
                    UILabel *rightLabel = [cell.contentView viewWithTag:4000 + i];
                    leftLabel.text = model.workName;
                    rightLabel.text = [NSString stringWithFormat:@"%@人", model.count];
                }
                
                UILabel *produceLabel = [cell.contentView viewWithTag:300 + indexPath.row];
                produceLabel.text = evaluateModel.remark;
                CGRect textViewHeight = [Utilities calculateWidthAndHeightWithWidth:SCREEN_WIDTH - 28 height:1000 text:evaluateModel.remark font:[UIFont systemFontOfSize:13]];
                CGFloat aHeight = textViewHeight.size.height - 20 > 0 ? textViewHeight.size.height - 20 : 0;
                CGFloat height = 20 + aHeight;
                if (height > 40) {
                    height = 40;
                }
                produceLabel.frame = CGRectMake(14, 40, SCREEN_WIDTH - 28, height);
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                
                return cell;
            }
        } else if (indexPath.section == 2) {
            if (indexPath.row == 0) {
                NSString *ID = @"cellID3";
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
                if (!cell) {
                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:ID];
                }
                if (![cell.contentView viewWithTag:400 + indexPath.row]) {
                    UILabel *producePointLabel = [[UILabel alloc] initWithFrame:CGRectMake(14, 0, 120, 44)];
                    producePointLabel.textColor = UIColorHexValue(0x4D4D4D);
                    producePointLabel.text = @"生产节点";
                    producePointLabel.tag = 400 + indexPath.row;
                    producePointLabel.font = [UIFont systemFontOfSize:15];
                    [cell.contentView addSubview:producePointLabel];
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                
                return cell;
            } else {
                EvaluateProducePointTableViewCell *cell = [[NSBundle mainBundle] loadNibNamed:@"EvaluateProducePointTableViewCell" owner:self options:nil].lastObject;
                cell.signBtn.imageView.layer.cornerRadius = 15;
                cell.signBtn.imageView.layer.masksToBounds = YES;
                cell.signBtn.tag = indexPath.row;
                if (indexPath.row == 1) {
                    [cell.signBtn setImage:[UIImage imageNamed:@"guanlizhe"] forState:UIControlStateNormal];
                } else {
                    [cell.signBtn setTitle:[NSString stringWithFormat:@"%ld", indexPath.row - 1] forState:UIControlStateNormal];
                }
                if (evaluateModel.spots.count > 0) {
                    EvaluateSpotsModel *model = evaluateModel.spots[indexPath.row - 1];
                    cell.nameLabel.text = model.workerName;
                    cell.produceNameLabel.text = model.workName;
                    [cell.signBtn sd_setImageWithURL:[NSURL URLWithString:model.workerIcon] forState:UIControlStateNormal];
                    [cell.signBtn addTarget:self action:@selector(onClickSignBtn:) forControlEvents:UIControlEventTouchUpInside];
                    if (model.wage && ![model.wage isKindOfClass:[NSNull class]] && model.wage.length>0) {
                        cell.priceLabel.text = [NSString stringWithFormat:@"%@元/小时", model.wage];
                    } else {
                        cell.priceLabel.text = [NSString stringWithFormat:@"%@元/小时", model.forecastWage];
                    }
                    [cell.timeBtn setTitle:[NSString stringWithFormat:@"%@h", model.hours] forState:UIControlStateNormal];
                    cell.evaluateBtn.tag = indexPath.row;
                    [cell.evaluateBtn addTarget:self action:@selector(onClickEvaluateSpotBtn:) forControlEvents:UIControlEventTouchUpInside];
                    if ([model.evaluated isEqualToString:@"1"]) {
                        [cell.evaluateBtn setTitle:@"已评价" forState:UIControlStateNormal];
                        [cell.evaluateBtn setBackgroundColor:RGB(179, 179, 179)];
                    }
                }
                if (indexPath.row == evaluateModel.spots.count) {
                    cell.lineLabel.hidden = YES;
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                
                return cell;
            }
        } else if (indexPath.section == 3) {
            UITableViewCell *cell = [[UITableViewCell alloc] init];
            if (![cell.contentView viewWithTag:500 + indexPath.row]) {
                UILabel *detailNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(110, 0, SCREEN_WIDTH - 110 - 33, 44)];
                detailNameLabel.numberOfLines = 0;
                detailNameLabel.textColor = UIColorHexValue(0x4D4D4D);
                detailNameLabel.tag = 500 + indexPath.row;
                detailNameLabel.font = [UIFont systemFontOfSize:14];
                [cell.contentView addSubview:detailNameLabel];
            }
            UILabel *detailNameLabel = [cell.contentView viewWithTag:500 + indexPath.row];
            if (indexPath.row == 1) {
                detailNameLabel.text = evaluateModel.deliveryAddress;
            } else if (indexPath.row == 2) {
                detailNameLabel.text = [NSString stringWithFormat:@"￥%@", evaluateModel.expressFee];
            } else if (indexPath.row == 3) {
                detailNameLabel.text = [NSString stringWithFormat:@"￥%@", evaluateModel.packingFee];
            } else if (indexPath.row == 4) {
                detailNameLabel.text = evaluateModel.packRemark;
            } else if (indexPath.row == 5) {
                if ([evaluateModel.packType isEqualToString:@"1"]) {
                    detailNameLabel.text = @"简易包装";
                } else if ([evaluateModel.packType isEqualToString:@"2"]) {
                    detailNameLabel.text = @"专业包装";
                }
            }
            
            if (indexPath.row == 0) {
                detailNameLabel.text = [NSString stringWithFormat:@"%ld张", evaluateModel.bomImgs.count];
                detailNameLabel.textAlignment = NSTextAlignmentRight;
                cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            } else {
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
            }
            cell.textLabel.textColor = UIColorHexValue(0x4D4D4D);
            cell.textLabel.font = [UIFont systemFontOfSize:15];
            cell.textLabel.text = _nameArr[indexPath.row];
            
            return cell;
        }
    } else if (_detailType == RECOMMENDTYPE) {
        JobDetailModel *detailModel = _jobDetailArr[0];
        if (indexPath.section == 0) {
            if (indexPath.row == 0) {
                NSString *ID = @"cellID";
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
                if (!cell) {
                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:ID];
                }
                if (!_jobKindLabel) {
                    _jobKindLabel = [[UILabel alloc] initWithFrame:CGRectMake(13, 0, 130, 50)];
                    _jobKindLabel.textColor = UIColorHexValue(0x8194C4);
                    _jobKindLabel.font = [UIFont systemFontOfSize:16];
                    [cell.contentView addSubview:_jobKindLabel];
                    UILabel *datelabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 150 - 12, 0, 150, 50)];
                    datelabel.tag = 600 + indexPath.row;
                    datelabel.textAlignment = NSTextAlignmentRight;
                    datelabel.textColor = UIColorHexValue(0x999999);
                    datelabel.font = [UIFont systemFontOfSize:12];
                    [cell.contentView addSubview:datelabel];
                }
                _jobKindLabel.text = detailModel.name;
                UILabel *datelabel = [cell.contentView viewWithTag:600 + indexPath.row];
                datelabel.text = [NSString stringWithFormat:@"%@-%@", detailModel.startDate, detailModel.endDate];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                
                return cell;
            } else {
                JobDetailMessageTableViewCell *cell = [[NSBundle mainBundle] loadNibNamed:@"JobDetailMessageTableViewCell" owner:self options:nil].lastObject;
                cell.nameLabel.text = detailModel.employerName;
                cell.kindLabel.text = detailModel.productCategoryName;
                cell.moneyLabel.text = detailModel.budget;
                cell.evaluateBtn.hidden = YES;
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                
                return cell;
            }
        } else if (indexPath.section == 1) {
            if (indexPath.row == 0) {
                NSString *ID = @"cellID1";
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
                if (!cell) {
                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:ID];
                }
                if (![cell.contentView viewWithTag:100 + indexPath.row]) {
                    UILabel *positionlabel = [[UILabel alloc] initWithFrame:CGRectMake(14, 0, 120, 50)];
                    positionlabel.textColor = UIColorHexValue(0x4D4D4D);
                    positionlabel.tag = 100 + indexPath.row;
                    positionlabel.font = [UIFont systemFontOfSize:15];
                    positionlabel.text = @"岗位描述";
                    [cell.contentView addSubview:positionlabel];
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                
                return cell;
            } else {
                NSString *ID = @"cellID2";
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
                if (!cell) {
                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:ID];
                }
                if (![cell.contentView viewWithTag:200 + indexPath.row]) {
                    UILabel *produceDetailLabel = [[UILabel alloc] initWithFrame:CGRectMake(14, 20, 120, 20)];
                    produceDetailLabel.textColor = UIColorHexValue(0x4D4D4D);
                    produceDetailLabel.tag = 200 + indexPath.row;
                    produceDetailLabel.text = @"生产说明:";
                    produceDetailLabel.font = [UIFont systemFontOfSize:13];
                    [cell.contentView addSubview:produceDetailLabel];
                }
                if (![cell.contentView viewWithTag:300 + indexPath.row]) {
                    UILabel *produceLabel = [[UILabel alloc] init];
                    produceLabel.textColor = UIColorHexValue(0x999999);
                    produceLabel.tag = 300 + indexPath.row;
                    produceLabel.font = [UIFont systemFontOfSize:13];
                    produceLabel.numberOfLines = 0;
                    produceLabel.frame = CGRectMake(14, 40, SCREEN_WIDTH - 28, 20);
                    [cell.contentView addSubview:produceLabel];
                }
                UILabel *produceLabel = [cell.contentView viewWithTag:300 + indexPath.row];
                produceLabel.text = detailModel.remark;
                CGRect textViewHeight = [Utilities calculateWidthAndHeightWithWidth:SCREEN_WIDTH - 28 height:1000 text:detailModel.remark font:[UIFont systemFontOfSize:13]];
                CGFloat aHeight = textViewHeight.size.height - 20 > 0 ? textViewHeight.size.height - 20 : 0;
                CGFloat height = 20 + aHeight;
                if (height > 40) {
                    height = 40;
                }
                produceLabel.frame = CGRectMake(14, 40, SCREEN_WIDTH - 28, height);
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                
                return cell;
            }
        } else if (indexPath.section == 2) {
            if (indexPath.row == 0) {
                NSString *ID = @"cellID3";
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
                if (!cell) {
                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:ID];
                }
                if (![cell.contentView viewWithTag:400 + indexPath.row]) {
                    UILabel *producePointLabel = [[UILabel alloc] initWithFrame:CGRectMake(14, 0, 120, 44)];
                    producePointLabel.textColor = UIColorHexValue(0x4D4D4D);
                    producePointLabel.text = @"生产节点";
                    producePointLabel.tag = 400 + indexPath.row;
                    producePointLabel.font = [UIFont systemFontOfSize:15];
                    [cell.contentView addSubview:producePointLabel];
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                
                return cell;
            } else {
                RecommendPointTableViewCell *cell = [[NSBundle mainBundle] loadNibNamed:@"RecommendPointTableViewCell" owner:self options:nil].lastObject;
                cell.recommendBtn.tag = indexPath.row;
                [cell.recommendBtn addTarget:self action:@selector(onClickRecommendBtn:) forControlEvents:UIControlEventTouchUpInside];
                cell.signBtn.imageView.layer.cornerRadius = 15;
                cell.signBtn.imageView.layer.masksToBounds = YES;
                cell.signBtn.tag = indexPath.row;
                if (indexPath.row == 1) {
                    [cell.signBtn setImage:[UIImage imageNamed:@"guanlizhe"] forState:UIControlStateNormal];
                }
                if (_statusNum == 1) {
                    if (detailModel.spots.count > 0) {
                        SpotsModel *model = detailModel.spots[indexPath.row - 1];
                        cell.nameLabel.text = model.workerName;
                        [cell.signBtn sd_setImageWithURL:[NSURL URLWithString:model.workerIcon] forState:UIControlStateNormal];
                        [cell.signBtn addTarget:self action:@selector(onClickSignBtn:) forControlEvents:UIControlEventTouchUpInside];
                    }
                    [cell.recommendBtn setTitle:@"待确认" forState:UIControlStateNormal];
                    cell.recommendBtn.enabled = NO;
                } else {
                    if (detailModel.spots.count > 0) {
                        SpotsModel *model = detailModel.spots[indexPath.row - 1];
                        if (model.workerName && ![model.workerName isKindOfClass:[NSNull class]]) {
                            cell.nameLabel.text = model.workerName;
                            [cell.recommendBtn setTitle:@"重选" forState:UIControlStateNormal];
                            [cell.signBtn sd_setImageWithURL:[NSURL URLWithString:model.workerIcon] forState:UIControlStateNormal];
                            [cell.signBtn addTarget:self action:@selector(onClickSignBtn:) forControlEvents:UIControlEventTouchUpInside];
                        } else {
                            [cell.signBtn setTitle:[NSString stringWithFormat:@"%ld", indexPath.row - 1] forState:UIControlStateNormal];
//                            cell.priceLabel.hidden = YES;
                            cell.nameLabel.text = model.remark;
                        }
                    }
                }
                
                if (detailModel.spots.count > 0) {
                    SpotsModel *model = detailModel.spots[indexPath.row - 1];
//                    cell.nameLabel.text = model.workerName;
                    cell.produceNameLabel.text = model.workName;
                    if (model.wage && ![model.wage isKindOfClass:[NSNull class]] && model.wage.length>0) {
                        cell.priceLabel.text = [NSString stringWithFormat:@"%@元/小时", model.wage];
                    } else {
                        cell.priceLabel.text = [NSString stringWithFormat:@"%@元/小时", model.forecastWage];
                    }
                }
                if (indexPath.row == detailModel.spots.count) {
                    cell.lineLabel.hidden = YES;
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                
                return cell;
            }
        } else if (indexPath.section == 3) {
            UITableViewCell *cell = [[UITableViewCell alloc] init];
            if (![cell.contentView viewWithTag:500 + indexPath.row]) {
                UILabel *detailNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(110, 0, SCREEN_WIDTH - 110 - 33, 44)];
                detailNameLabel.numberOfLines = 0;
                detailNameLabel.textColor = UIColorHexValue(0x4D4D4D);
                detailNameLabel.tag = 500 + indexPath.row;
                detailNameLabel.font = [UIFont systemFontOfSize:14];
                [cell.contentView addSubview:detailNameLabel];
            }
            UILabel *detailNameLabel = [cell.contentView viewWithTag:500 + indexPath.row];
            if (indexPath.row == 1) {
                detailNameLabel.text = detailModel.deliveryAddress;
            } else if (indexPath.row == 2) {
                detailNameLabel.text = [NSString stringWithFormat:@"￥%@", detailModel.expressFee];
            } else if (indexPath.row == 3) {
                detailNameLabel.text = [NSString stringWithFormat:@"￥%@", detailModel.packingFee];
            } else if (indexPath.row == 4) {
                detailNameLabel.text = detailModel.packRemark;
            } else if (indexPath.row == 5) {
                if ([detailModel.packType isEqualToString:@"1"]) {
                    detailNameLabel.text = @"简易包装";
                } else if ([detailModel.packType isEqualToString:@"2"]) {
                    detailNameLabel.text = @"专业包装";
                }
            }
            
            if (indexPath.row == 0) {
                detailNameLabel.text = [NSString stringWithFormat:@"%ld张", detailModel.bomImgs.count];
                detailNameLabel.textAlignment = NSTextAlignmentRight;
                cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            } else {
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
            }
            cell.textLabel.textColor = UIColorHexValue(0x4D4D4D);
            cell.textLabel.font = [UIFont systemFontOfSize:15];
            cell.textLabel.text = _nameArr[indexPath.row];
            
            return cell;
        }
    }
    return nil;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 3) {
        if (indexPath.row == 0) {
            DataPicturesViewController *dataPicturesVC = [[DataPicturesViewController alloc] init];
            if (_detailType == EVALUATETYPE) {
                EvaluateModel *detailModel = _jobDetailArr[0];
                dataPicturesVC.imageArr = detailModel.bomImgs;
            } else {
                JobDetailModel *detailModel = _jobDetailArr[0];
                dataPicturesVC.imageArr = detailModel.bomImgs;
            }
            dataPicturesVC.pictureType = BOMIMAGETYPE;
            [self.navigationController pushViewController:dataPicturesVC animated:YES];
        }
    }
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (void)onClickCheckJob {
    WEAKSELF;
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [HYBaseHandler requestProjectCheckParmers:@{@"projectId" : _ID} Success:^(id obj)
     {
         [MBProgressHUD hideAllHUDsForView:weakSelf.view animated:YES];
         if ([obj server_Getcodecheck])
         {
             NSLog(@"%@", obj);
             JobDetailViewController *jobDetailVC = [[JobDetailViewController alloc] init];
             jobDetailVC.detailType = EVALUATETYPE;
             jobDetailVC.ID = _ID;
             [self.navigationController pushViewController:jobDetailVC animated:YES];
         }
         else
         {
             [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
         }
     } failed:^(NSError *error) {
         [MBProgressHUD hideAllHUDsForView:weakSelf.view animated:YES];
         
     }];
}

- (void)onClickEvaluateEmployerBtn {
    EvaluateModel *evaluateModel = _jobDetailArr[0];
    AppraiseViewController *appraiseVC = [[AppraiseViewController alloc] init];
    appraiseVC.projectID = _ID;
    appraiseVC.raiseID = evaluateModel.employerId;
    [self.navigationController pushViewController:appraiseVC animated:YES];
}

- (void)onClickEvaluateSpotBtn:(UIButton *)sender {
    EvaluateModel *evaluateModel = _jobDetailArr[0];
    AppraiseViewController *appraiseVC = [[AppraiseViewController alloc] init];
    EvaluateSpotsModel *spotModel = evaluateModel.spots[sender.tag - 1];
    appraiseVC.projectID = _ID;
    appraiseVC.raiseID = spotModel.workerUserId;
    [self.navigationController pushViewController:appraiseVC animated:YES];
}

- (void)onClickRecommendBtn:(UIButton *)sender {
    SelectWorkerViewController *selectWorkerVC = [[SelectWorkerViewController alloc] init];
    JobDetailModel *detailModel = _jobDetailArr[0];
    SpotsModel *model = detailModel.spots[sender.tag - 1];
    selectWorkerVC.spotsId = model.ID;
    [self.navigationController pushViewController:selectWorkerVC animated:YES];
}

- (void)onClickSignBtn:(UIButton *)sender {
    
    if (_detailType == EVALUATETYPE) {
        EvaluateModel *evaluateModel = _jobDetailArr[0];
        EvaluateSpotsModel *model = evaluateModel.spots[sender.tag - 1];
        if (model.workerName && ![model.workerName isEqual:@""]) {
            WorkerMessagesViewController *messageVC = [[WorkerMessagesViewController alloc] init];
            messageVC.ID = model.worker.ID;
            messageVC.targetId = model.worker.user.ID;
            [self.navigationController pushViewController:messageVC animated:YES];
        }
    } else {
        JobDetailModel *detailModel = _jobDetailArr[0];
        SpotsModel *model = detailModel.spots[sender.tag - 1];
        if (model.workerName && ![model.workerName isEqual:@""]) {
            WorkerMessagesViewController *messageVC = [[WorkerMessagesViewController alloc] init];
            messageVC.ID = model.worker.ID;
            messageVC.targetId = model.worker.user.ID;
            [self.navigationController pushViewController:messageVC animated:YES];
        }
    }
}

- (void)onClickEnsureProject {
    WEAKSELF;
//    JobDetailModel *detailModel = _jobDetailArr[0];
//
//    for (int i = 0; i < detailModel.spots.count; i++) {
//        SpotsModel *model = detailModel.spots[i];
//        if (![model.confirm isEqual:@"1"]) {
//            [LTools showMBProgressWithText:@"等待工人确定后,才可以支付" addToView:self.view];
//            return;
//        }
//    }
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [HYBaseHandler requestEnsureProjectParmers:@{@"id" : _ID} Success:^(id obj)
     {
         [MBProgressHUD hideAllHUDsForView:weakSelf.view animated:YES];
         if ([obj server_Getcodecheck])
         {
             NSLog(@"%@", obj);
             [self.navigationController popViewControllerAnimated:YES];
         }
         else
         {
             [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
         }
     } failed:^(NSError *error) {
         [MBProgressHUD hideAllHUDsForView:weakSelf.view animated:YES];
         
     }];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
